// packageA/share/share.js
import  { invite } from "../../common/api/share";
import {
  getQrCode,
} from '../../common/api/my'
import dayjs from "dayjs";
Page({

  /**
   * 页面的初始数据
   */
  data: {
      list: [],
      count: 0,
      price:0,
      visible:false,
      codeUrl:"",
  },

  onLoad(){
    this.getData();
  },

  // 跳转
  go(e) {
    const { index } = e.currentTarget.dataset;
    let item = this.data.list[index];
    wx.navigateTo({
      url: "/pages/shareRecords/shareRecords?id=" + item.id
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(e) {
    let user = wx.getStorageSync('userInfo');
    console.log(e);
    return {
      title: "杆赢天下，求胜未来。一元乐享好球杆，千万球友的选择",
      imageUrl: "../../images/shareImg.jpg",
       path: "/pages/index/index?id=" + user.id
    }
  },
  async getData(){
    let user = wx.getStorageSync('userInfo');
    let res = await invite({
      userId: user.id
    });
    res.users.forEach(e => {
      e.time = dayjs(e.createTime).format("YYYY-MM-DD") ;
    })
    this.setData({
      list: res.users || [],
      count: res.count,
      price: res.price
    });
  },

  openDialog:async function(){
    let user = wx.getStorageSync('userInfo');
    let data = {
      userId: user.id,
      code: wx.getStorageSync('token'),
    };
    let res = await getQrCode(data);
    console.log(res)
    this.setData({
      codeUrl: res,
      visible:true
    });
  },

  closeDialog(){
    this.setData({
      visible:false
    })
  },
})